<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="由程序产生" prop="id">
      <el-input v-model="dataForm.id" placeholder="由程序产生"></el-input>
    </el-form-item>
    <el-form-item label="人员分类" prop="ptype">
      <el-input v-model="dataForm.ptype" placeholder="人员分类"></el-input>
    </el-form-item>
    <el-form-item label="是否为真实意思表示" prop="sfyyzs">
      <el-input v-model="dataForm.sfyyzs" placeholder="是否为真实意思表示"></el-input>
    </el-form-item>
    <el-form-item label="是否为共有房屋" prop="sfgy">
      <el-input v-model="dataForm.sfgy" placeholder="是否为共有房屋"></el-input>
    </el-form-item>
    <el-form-item label="是否证件遗失" prop="sfzjys">
      <el-input v-model="dataForm.sfzjys" placeholder="是否证件遗失"></el-input>
    </el-form-item>
    <el-form-item label="是否证件一致" prop="sfzjyz">
      <el-input v-model="dataForm.sfzjyz" placeholder="是否证件一致"></el-input>
    </el-form-item>
    <el-form-item label="其他询问事项内容" prop="qtxwsxnr">
      <el-input v-model="dataForm.qtxwsxnr" placeholder="其他询问事项内容"></el-input>
    </el-form-item>
    <el-form-item label="其他询问事项" prop="qtxwsx">
      <el-input v-model="dataForm.qtxwsx" placeholder="其他询问事项"></el-input>
    </el-form-item>
    <el-form-item label="询问时间" prop="xwsj">
      <el-input v-model="dataForm.xwsj" placeholder="询问时间"></el-input>
    </el-form-item>
    <el-form-item label="询问人" prop="xwr">
      <el-input v-model="dataForm.xwr" placeholder="询问人"></el-input>
    </el-form-item>
    <el-form-item label="被询问人" prop="bxwr">
      <el-input v-model="dataForm.bxwr" placeholder="被询问人"></el-input>
    </el-form-item>
    <el-form-item label="被询问人签名" prop="bxwrqm">
      <el-input v-model="dataForm.bxwrqm" placeholder="被询问人签名"></el-input>
    </el-form-item>
    <el-form-item label="联系方式" prop="lxfs">
      <el-input v-model="dataForm.lxfs" placeholder="联系方式"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          seqno: 0,
          id: '',
          ptype: '',
          sfyyzs: '',
          sfgy: '',
          sfzjys: '',
          sfzjyz: '',
          qtxwsxnr: '',
          qtxwsx: '',
          xwsj: '',
          xwr: '',
          bxwr: '',
          bxwrqm: '',
          lxfs: ''
        },
        dataRule: {
          id: [
            { required: true, message: '由程序产生不能为空', trigger: 'blur' }
          ],
          ptype: [
            { required: true, message: '人员分类不能为空', trigger: 'blur' }
          ],
          sfyyzs: [
            { required: true, message: '是否为真实意思表示不能为空', trigger: 'blur' }
          ],
          sfgy: [
            { required: true, message: '是否为共有房屋不能为空', trigger: 'blur' }
          ],
          sfzjys: [
            { required: true, message: '是否证件遗失不能为空', trigger: 'blur' }
          ],
          sfzjyz: [
            { required: true, message: '是否证件一致不能为空', trigger: 'blur' }
          ],
          qtxwsxnr: [
            { required: true, message: '其他询问事项内容不能为空', trigger: 'blur' }
          ],
          qtxwsx: [
            { required: true, message: '其他询问事项不能为空', trigger: 'blur' }
          ],
          xwsj: [
            { required: true, message: '询问时间不能为空', trigger: 'blur' }
          ],
          xwr: [
            { required: true, message: '询问人不能为空', trigger: 'blur' }
          ],
          bxwr: [
            { required: true, message: '被询问人不能为空', trigger: 'blur' }
          ],
          bxwrqm: [
            { required: true, message: '被询问人签名不能为空', trigger: 'blur' }
          ],
          lxfs: [
            { required: true, message: '联系方式不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.seqno = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.seqno) {
            this.$http({
              url: this.$http.adornUrl(`/bdc/bdcxwbl/info/${this.dataForm.seqno}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.id = data.bdcXwbl.id
                this.dataForm.ptype = data.bdcXwbl.ptype
                this.dataForm.sfyyzs = data.bdcXwbl.sfyyzs
                this.dataForm.sfgy = data.bdcXwbl.sfgy
                this.dataForm.sfzjys = data.bdcXwbl.sfzjys
                this.dataForm.sfzjyz = data.bdcXwbl.sfzjyz
                this.dataForm.qtxwsxnr = data.bdcXwbl.qtxwsxnr
                this.dataForm.qtxwsx = data.bdcXwbl.qtxwsx
                this.dataForm.xwsj = data.bdcXwbl.xwsj
                this.dataForm.xwr = data.bdcXwbl.xwr
                this.dataForm.bxwr = data.bdcXwbl.bxwr
                this.dataForm.bxwrqm = data.bdcXwbl.bxwrqm
                this.dataForm.lxfs = data.bdcXwbl.lxfs
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/bdc/bdcxwbl/${!this.dataForm.seqno ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'seqno': this.dataForm.seqno || undefined,
                'id': this.dataForm.id,
                'ptype': this.dataForm.ptype,
                'sfyyzs': this.dataForm.sfyyzs,
                'sfgy': this.dataForm.sfgy,
                'sfzjys': this.dataForm.sfzjys,
                'sfzjyz': this.dataForm.sfzjyz,
                'qtxwsxnr': this.dataForm.qtxwsxnr,
                'qtxwsx': this.dataForm.qtxwsx,
                'xwsj': this.dataForm.xwsj,
                'xwr': this.dataForm.xwr,
                'bxwr': this.dataForm.bxwr,
                'bxwrqm': this.dataForm.bxwrqm,
                'lxfs': this.dataForm.lxfs
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
